<template>
  <!-- 需求单 -->
  <div>
    <!-- 第一行 -->
    <el-row>
      <el-col span="2.5">
        <el-button icon="el-icon-menu">
          黄金品类
        </el-button>
      </el-col>
      <el-col span="2.5">
        <el-button icon="el-icon-printer"
                   @click="daochu">
          导出
        </el-button>
      </el-col>
      <el-col span="6">
        <el-date-picker v-model="date"
                        :default-time="['00:00:00', '23:59:59']"
                        type="daterange"
                        format="yyyy-MM-dd"
                        value-format="timestamp"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @blur="searchDate" />
      </el-col>
      <el-col span="1">
        <div> &nbsp;</div>
      </el-col>
      <el-col span="4">
        <el-input v-model="input"
                  placeholder="请输入内容" />
      </el-col>
      <el-col span="2">
        <el-button type="primary"
                   icon="el-icon-search"
                   @click="search">搜索</el-button>

      </el-col>
      <el-col span="3">
        <el-button circle="true"
                   icon="el-icon-delete-solid" />
        <el-button circle="true"
                   icon="el-icon-refresh"
                   @click="refresh()" />

      </el-col>
    </el-row>
    <div style="">
      <el-button type="danger"
                 size="mini"
                 @click="removeRows()">批量结算</el-button>
    </div>
    <!-- 表格 -->

    <el-table :data="tableData1"
              style="width: 100%"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection"
                       width="55" />
      <el-table-column prop="productInfo"
                       align="center"
                       label="产品信息"
                       width="180" />
      <el-table-column prop="customer"
                       align="center"
                       label="客户"
                       width="100" />
      <el-table-column prop="productName"
                       align="center"
                       label="产品名称"
                       width="200" />
      <el-table-column prop="condition"
                       align="center"
                       label="成色"
                       width="80" />
      <el-table-column prop="weight"
                       align="center"
                       label="重量"
                       width="80" />
      <el-table-column prop="nums"
                       align="center"
                       label="数量"
                       width="100" />
      <el-table-column prop="perGram"
                       align="center"
                       label="克工费"
                       width="170" />
      <el-table-column prop="date"
                       align="center"
                       label="操作"
                       width="100"
                       height="2200">

        <template slot-scope="scope">

          <el-button type="success"
                     size="mini"
                     @click="open2">结算</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination @size-change="Size"
                     @current-change="Current"
                     :current-page="currentPage4"
                     :page-sizes="[10, 20, 30, 40]"
                     :page-size="100"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="tableData1.total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import list from '@/api/sale/amount/amountList'

export default {
  inject: ['reload'],
  data () {
    return {
      input: '',
      // date: '',
      // 结算单列表
      tableData: [],
      // 分页
      pageNum: 1,
      pageSize: 10,
      total: null,
      date: ['null', 'null'],
      tableData1: [],
      pid: '',
      multipleSelection: [],// 批量选择中选择的记录列表
      superid: null,
      totalids: {
        psId: null,
        ids: []
      }
    }
  },
  created () {
    // 展示需求表
    this.start()
  },
  methods: {
    open2 () {
      this.$confirm('请确认该商品已经结算完成, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var ids = []
        for (var index = 0; index < this.multipleSelection.length; index++) {
          var obj = this.multipleSelection[index]
          var i = obj.id
          ids.push(i)
        }
        this.totalids.ids = ids
        list.updateStatus(this.totalids).then(res => {
          console.log(res);
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '结算成功!'
            });
          }
        })
        this.$message({
          type: 'success',
          message: '结算成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },

    //获取选择复选框的id值
    handleSelectionChange (selection) {
      this.multipleSelection = selection
    },
    daochu () {
      need.daochu().then(result => {
        console.log(result)
        this.$message({
          message: '导出成功',
          type: 'success',
        })
      })
    },
    //批量结算
    removeRows () {
      this.$confirm('请确认该商品已经结算完成, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var ids = []
        for (var index = 0; index < this.multipleSelection.length; index++) {
          var obj = this.multipleSelection[index]
          var i = obj.id
          ids.push(i)
        }
        this.totalids.ids = ids
        list.updateStatus(this.totalids).then(res => {
          console.log(res);
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '结算成功!'
            });
          }
        })
        this.$message({
          type: 'success',
          message: '结算成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    // search() {
    //   // 按输入入库编号查
    //   // alert(this.date);
    // },
    search () {
      // 清空
      this.tableData = []
      if (this.input === '') {
        this.$message.error('请输入查询信息')
        return
      }
      const orderNum = this.input
      needallocation.info(orderNum).then(result => {
        // this.tableData = result.data
      })
    },
    // 刷新页面
    refresh () {
      this.reload()
    },
    // 分页
    start () {

      this.psId = this.$route.params.id

      console.log("***************" + this.$route.params.id);
      this.totalids.psId = this.psId
      list.findAll(this.psId).then(result => {
        console.log(result);
        this.tableData1 = result.data.ChooseProduceMsgDto
      })
    }
  }
}
</script>

<style scoped>
</style>
